package com.ruoyi.web.controller.warehouse;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.AWmProduct;
import com.ruoyi.system.service.IAWmProductService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品（含库存信息）Controller
 * 
 * @author ruoyi
 * @date 2025-03-27
 */
@RestController
@RequestMapping("/system/product")
public class AWmProductController extends BaseController
{
    @Autowired
    private IAWmProductService aWmProductService;

    /**
     * 查询商品（含库存信息）列表
     */
    @PreAuthorize("@ss.hasPermi('system:product:list')")
    @GetMapping("/list")
    public TableDataInfo list(AWmProduct aWmProduct)
    {
        startPage();
        List<AWmProduct> list = aWmProductService.selectAWmProductList(aWmProduct);
        return getDataTable(list);
    }

    /**
     * 导出商品（含库存信息）列表
     */
    @PreAuthorize("@ss.hasPermi('system:product:export')")
    @Log(title = "商品（含库存信息）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AWmProduct aWmProduct)
    {
        List<AWmProduct> list = aWmProductService.selectAWmProductList(aWmProduct);
        ExcelUtil<AWmProduct> util = new ExcelUtil<AWmProduct>(AWmProduct.class);
        util.exportExcel(response, list, "商品（含库存信息）数据");
    }

    /**
     * 获取商品（含库存信息）详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:product:query')")
    @GetMapping(value = "/{productId}")
    public AjaxResult getInfo(@PathVariable("productId") Long productId)
    {
        return success(aWmProductService.selectAWmProductByProductId(productId));
    }

    /**
     * 新增商品（含库存信息）
     */
    @PreAuthorize("@ss.hasPermi('system:product:add')")
    @Log(title = "商品（含库存信息）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AWmProduct aWmProduct)
    {
        return toAjax(aWmProductService.insertAWmProduct(aWmProduct));
    }

    /**
     * 修改商品（含库存信息）
     */
    @PreAuthorize("@ss.hasPermi('system:product:edit')")
    @Log(title = "商品（含库存信息）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AWmProduct aWmProduct)
    {
        return toAjax(aWmProductService.updateAWmProduct(aWmProduct));
    }

    /**
     * 删除商品（含库存信息）
     */
    @PreAuthorize("@ss.hasPermi('system:product:remove')")
    @Log(title = "商品（含库存信息）", businessType = BusinessType.DELETE)
	@DeleteMapping("/{productIds}")
    public AjaxResult remove(@PathVariable Long[] productIds)
    {
        return toAjax(aWmProductService.deleteAWmProductByProductIds(productIds));
    }
}
